<?php
require_once APPPATH . "controllers/cmsbase.php";
class cms_options extends CmsBase {

	var $_require_login = true;

	function __construct() {
		parent :: __construct();
		// Check permission
		parent::_check_permission('pms_option');
		$this->load->model('model_option', 'model_option');
	}

	/**
	 *
	 *
	 */
	function index() {
		$options = $this->model_option->find_all();
		return $this->_render_my_view(array ('options' => $options));
	}

	/**
	 *
	 *
	 */
	function add() {
		if ($this->input->post('Submit')) {
			$data = parse_input("item_", $_POST);
			$this->model_option->insert($data);
			redirect(site_url(array("c" => "cms_options", "m" => "index")));
		}
		return $this->_render_my_view(array());
	}
	/**
	 *
	 *
	 */
	function delete($id) {
		if(intval($id)){
			$this->model_option->delete($id);
		}
		redirect(site_url(array("c" => "cms_options", "m" => "index")));
	}
	/**
	 *
	 *
	 */
	function edit($id) {
		if(intval($id)){
			if ($this->input->post('Submit')) {
				$data = parse_input("item_", $_POST);
				$this->model_option->update($id, $data);
			}
			else{
				$option = $this->model_option->find($id);
				return $this->_render_my_view(array ('option' => $option));
			}
		}
		redirect(site_url(array("c" => "cms_options", "m" => "index")));
	}
}
?>
